<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="学生姓名" prop="studentName">
        <el-input v-model="queryParams.studentName" placeholder="请输入学生姓名" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="年级" prop="gradeName">
        <el-input v-model="queryParams.gradeName" placeholder="请输入年级" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="班级" prop="className">
        <el-input v-model="queryParams.className" placeholder="请输入班级" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <!-- <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['com/ruoyi/business:records:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['com/ruoyi/business:records:edit']"
        >修改</el-button>
      </el-col> -->
      <!--      <el-col :span="1.5">-->
      <!--        <el-button-->
      <!--          type="danger"-->
      <!--          plain-->
      <!--          icon="el-icon-delete"-->
      <!--          size="mini"-->
      <!--          :disabled="multiple"-->
      <!--          @click="handleDelete"-->
      <!--          v-hasPermi="['business:records:remove']"-->
      <!--        >批量删除</el-button>-->
      <!--      </el-col>-->
      <!-- <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['com/ruoyi/business:records:export']"
        >导出</el-button>
      </el-col> -->
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table border stripe :header-cell-style="rowClass" v-loading="loading" :data="recordsList"
      @selection-change="handleSelectionChange">
      <!-- <el-table-column :resizable="false" type="selection" width="55" align="center" /> -->
      <el-table-column :resizable="false" type="index" width="55" align="center" label="序号" />
      <el-table-column :resizable="false" label="学生姓名" align="center" prop="studentName" />
      <el-table-column :resizable="false" label="年级" align="center" prop="gradeName" />
      <el-table-column :resizable="false" label="班级" align="center" prop="className" />
      <el-table-column :resizable="false" label="学校审批状态" align="center" prop="schoolApprovalStatus">
        <template slot-scope="scope">
          <div v-if="scope.row.schoolApprovalStatus == 0" class="flex gap-2">
            <el-tag type="info" effect="dark">
              待审核
            </el-tag>
          </div>
          <div v-else-if="scope.row.schoolApprovalStatus == 1" class="flex gap-2">
            <el-tag type="success" effect="dark">
              审批通过
            </el-tag>
          </div>
          <div v-else class="flex gap-2">
            <el-tag type="danger" effect="dark">
              拒绝
            </el-tag>
          </div>
        </template>
      </el-table-column>
      <el-table-column :resizable="false" label="请假开始和结束时间" align="center" prop="schoolApprovalTime" width="180">
        <template slot-scope="scope">
          <div>{{ parseTime(scope.row.startTime) }}</div>
          <div>{{ parseTime(scope.row.endTime) }}</div>
        </template>
      </el-table-column>
      <el-table-column :resizable="false" label="学校审批时间" align="center" prop="schoolApprovalTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.schoolApprovalTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column :resizable="false" label="学校审批意见" align="center" prop="schoolComment" />
      <el-table-column :resizable="false" label="餐费退款状态" align="center" prop="payoutStatus">
        <template slot-scope="scope">
          <div v-if="scope.row.payoutStatus == 2" class="flex gap-2">
            <el-tag type="info" effect="dark">
              待审核
            </el-tag>
          </div>
          <div v-else-if="scope.row.payoutStatus == 1" class="flex gap-2">
            <el-tag type="success" effect="dark">
              已退款
            </el-tag>
          </div>
          <div v-else class="flex gap-2">
            <el-tag type="danger" effect="dark">
              拒绝
            </el-tag>
          </div>
        </template>
      </el-table-column>
      <el-table-column :resizable="false" label="退款审批意见" align="center" prop="payoutRemarks" />
      <el-table-column :resizable="false" label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button v-if="scope.row.payoutStatus !== 1" size="mini" type="text" icon="el-icon-delete"
            @click="handleDelete(scope.row)" v-hasPermi="['business:leaves:remove']">删除</el-button>
          <el-button class="btn" @click="Drawer(scope.row)" type="text">详情</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />

    <!-- 添加或修改请假审批记录对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="请假ID" prop="leaveId">
          <el-input v-model="form.leaveId" placeholder="请输入请假ID" />
        </el-form-item>
        <el-form-item label="学校ID" prop="schoolId">
          <el-input v-model="form.schoolId" placeholder="请输入学校ID" />
        </el-form-item>
        <el-form-item label="学校审批人ID" prop="schoolApproverId">
          <el-input v-model="form.schoolApproverId" placeholder="请输入学校审批人ID" />
        </el-form-item>
        <el-form-item label="逻辑删除标记，0=未删除，1=已删除" prop="isDeleted">
          <el-input v-model="form.isDeleted" placeholder="请输入逻辑删除标记，0=未删除，1=已删除" />
        </el-form-item>
        <el-form-item label="学校审批时间" prop="schoolApprovalTime">
          <el-date-picker clearable v-model="form.schoolApprovalTime" type="date" value-format="yyyy-MM-dd"
            placeholder="请选择学校审批时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="学校审批意见" prop="schoolComment">
          <el-input v-model="form.schoolComment" placeholder="请输入学校审批意见" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
    <!-- drawer -->
    <el-drawer title="详情" :visible.sync="drawer" direction="rtl" size="732px">
      <div class="drawercontent" v-loading="drawerloading">
        <div class="line"></div>
        <div style="margin-top: 10px;">
          <el-descriptions :border="true" :column="1"
            :labelStyle="{ width: '150px', textAlign: 'center', color: '#000' }" :contentStyle="{ color: '#000' }">
            <el-descriptions-item label="学生姓名">
              {{ drawerData.studentName }}
            </el-descriptions-item>
            <el-descriptions-item label="年级">
              {{ drawerData.gradeName }}
            </el-descriptions-item>
            <el-descriptions-item label="班级">
              {{ drawerData.className }}
            </el-descriptions-item>
            <el-descriptions-item label="学校审批状态">
              <div v-if="drawerData.schoolApprovalStatus == 0" class="flex gap-2">
                <el-tag type="info" effect="dark">
                  待审核
                </el-tag>
              </div>
              <div v-else-if="drawerData.schoolApprovalStatus == 1" class="flex gap-2">
                <el-tag type="success" effect="dark">
                  审批通过
                </el-tag>
              </div>
              <div v-else class="flex gap-2">
                <el-tag type="danger" effect="dark">
                  拒绝
                </el-tag>
              </div>
            </el-descriptions-item>
            <el-descriptions-item label="请假开始和结束时间">
              <div>{{ parseTime(drawerData.startTime) }}   {{ parseTime(drawerData.endTime) }}</div>
            </el-descriptions-item>
            <el-descriptions-item label="学校审批时间">
              <span>{{ parseTime(drawerData.schoolApprovalTime) }}</span>
            </el-descriptions-item>
            <el-descriptions-item label="学校审批意见">
              {{ drawerData.schoolComment }}
            </el-descriptions-item>
            <el-descriptions-item label="餐费退款状态">
              <div v-if="drawerData.payoutStatus == 2" class="flex gap-2">
                <el-tag type="info" effect="dark">
                  待审核
                </el-tag>
              </div>
              <div v-else-if="drawerData.payoutStatus == 1" class="flex gap-2">
                <el-tag type="success" effect="dark">
                  已退款
                </el-tag>
              </div>
              <div v-else class="flex gap-2">
                <el-tag type="danger" effect="dark">
                  拒绝
                </el-tag>
              </div>
            </el-descriptions-item>
            <el-descriptions-item label="退款审批意见">
              {{ drawerData.payoutRemarks }}
            </el-descriptions-item>
          </el-descriptions>
        </div>
      </div>
    </el-drawer>
  </div>
</template>

<script>
import { listRecords, getRecords, delRecords, addRecords, updateRecords } from "@/api/leaveSystem/leaveRecord";

export default {
  name: "Records",
  data () {
    return {
      drawer: false,
      // 遮罩层
      loading: true,
      drawerloading: true,
      // 选中数组
      ids: [],
      // 选中学生名字数组
      studentNames: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 请假审批记录表格数据
      recordsList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        leaveId: null,
        schoolId: null,
        schoolApproverId: null,
        isDeleted: null,
        parentApprovalStatus: null,
        schoolApprovalStatus: null,
        schoolApprovalTime: null,
        schoolComment: null,
        studentName: null,
        className: null,
        gradeName: null
      },
      //详情数据
      drawerData: {},
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        leaveId: [
          { required: true, message: "请假ID不能为空", trigger: "blur" }
        ],
        schoolId: [
          { required: true, message: "学校ID不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created () {
    this.getList();
  },
  methods: {
    // 详情
    Drawer (data) {
      this.drawer = true
      this.drawerloading = true
      // let res = await refundDetails(data.id)
      this.drawerData = data
      this.drawerloading = false
      console.log("=====>", this.drawerData);
    },
    //设置table标题样式
    rowClass ({ row, rowIndex }) {
      return 'font-size: 15px; background-color: #FAFAFA;'
    },
    /** 查询请假审批记录列表 */
    getList () {
      this.loading = true;
      listRecords(this.queryParams).then(response => {
        this.recordsList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel () {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset () {
      this.form = {
        id: null,
        leaveId: null,
        schoolId: null,
        schoolApproverId: null,
        isDeleted: null,
        parentApprovalStatus: null,
        schoolApprovalStatus: null,
        schoolApprovalTime: null,
        schoolComment: null,
        studentName: null,
        className: null,
        gradeName: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery () {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery () {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange (selection) {
      this.ids = selection.map(item => item.leaveId)
      this.studentNames = selection.map(item => item.studentName)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    // handleAdd() {
    //   this.reset();
    //   this.open = true;
    //   this.title = "添加请假审批记录";
    // },
    /** 修改按钮操作 */
    // handleUpdate(row) {
    //   this.reset();
    //   const id = row.id || this.ids
    //   getRecords(id).then(response => {
    //     this.form = response.data;
    //     this.open = true;
    //     this.title = "修改请假审批记录";
    //   });
    // },
    /** 提交按钮 */
    submitForm () {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateRecords(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addRecords(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete (row) {
      const ids = row.leaveId || this.ids;
      const name = row.studentName || this.studentNames
      // this.$modal.confirm('是否确认删除请假审批记录编号为"' + ids + '"的数据项？').then(function() {
      this.$modal.confirm('是否确认删除请假审批姓名为"' + name + '"的数据项？').then(function () {
        return delRecords(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => { });
    },
    /** 导出按钮操作 */
    handleExport () {
      this.download('business/records/export', {
        ...this.queryParams
      }, `records_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
<style lang="scss" scoped>
.drawercontent {
  padding: 0 20px 20px;
  box-sizing: border-box;

  .line {
    border: 1px solid #ECECEC;
    width: 100%;
  }

  .item {
    margin-top: 10px;

    .title {
      font-size: 16px;
      font-weight: bold;
      position: relative;
      z-index: 0;

      .line {
        position: absolute;
        top: 12px;
        left: 0;
        z-index: -1;
        width: 100%;
        height: 8px;
        border-radius: 5px;
        background-color: #FFCE80;
      }
    }
  }
}
</style>
